package logic

import (
	"context"
	"shopping-cart/model"

	"shopping-cart/cartrpc/cartrpc"
	"shopping-cart/cartrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartListLogic) CartList(in *cartrpc.CartListRequest) (*cartrpc.CartListResponse, error) {
	// todo: add your logic here and delete this line

	var carts []model.Cart
	model.DB.Debug().Find(&carts)
	var cartList []*cartrpc.CartList
	for _, cart := range carts {

		list := cartrpc.CartList{
			ShopId:   int64(cart.ShopId),
			Quantity: int64(cart.Quantity),
			Money:    float32(cart.Money),
		}
		cartList = append(cartList, &list)
	}
	return &cartrpc.CartListResponse{
		List: cartList,
	}, nil
}
